package timing.ukulele.flow.config;

import timing.ukulele.flow.extention.CustomBpmnJsonConverter;
import timing.ukulele.flow.extention.IdWorkerGenerator;
import org.activiti.spring.SpringProcessEngineConfiguration;
import org.activiti.spring.boot.ProcessEngineConfigurationConfigurer;
import org.springframework.context.annotation.Configuration;

@Configuration
//@AutoConfigureAfter(name = {" org.activiti.spring.SpringProcessEngineConfiguration","timing.ukulele.cache.redis.RedisCache"})
public class ActivitiAutoConfiguration implements ProcessEngineConfigurationConfigurer {
//    private final RedisCache redisCache;
//    private final RedisTemplate<String,Object> redisTemplate;

//    public ActivitiAutoConfiguration(RedisCache redisCache, RedisTemplate<String, Object> redisTemplate) {
//        this.redisCache = redisCache;
//        this.redisTemplate = redisTemplate;
//        this.redisTemplate.setEnableTransactionSupport(Boolean.FALSE);
//    }


    @Override
    public void configure(SpringProcessEngineConfiguration springProcessEngineConfiguration) {
        //分布式递增id生成器
        IdWorkerGenerator idGenerator = new IdWorkerGenerator();
        springProcessEngineConfiguration.setIdGenerator(idGenerator);
        springProcessEngineConfiguration.getProcessEngineConfiguration().setIdGenerator(idGenerator);
        // 配置自定义用户任务解析器
        CustomBpmnJsonConverter.initCustomJsonConverter();
        //分布式缓存 todo 存在序列化和反序列化问题
//        springProcessEngineConfiguration.getProcessEngineConfiguration().setProcessDefinitionCache(new DistributedCache(redisCache));
    }
}
